package com.ebelter.seneo.ui.fragments.infos;


import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.utils.StringUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.btcomlib.utils.log.LogUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.fragments.main.Info_Fragment;
import com.ebelter.seneo.ui.views.LevelView;


//填写密码
public class Info_BMI_Fragment extends BaseFragment  implements Info_Fragment.IInfoUpdateInterface {

    public static final String TAG = "Info_BMI_Fragment";
    TextView infofly_value_tv;
    TextView infofly_valueunit_tv;
    TextView infofly_tip1_tv;
    LevelView info_levelview;

    @Override
    protected int setLayoutResouceId() {
        return R.layout.info_fly1;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        infofly_value_tv=findViewById(R.id.infofly_value_tv);
        infofly_valueunit_tv=findViewById(R.id.infofly_valueunit_tv);
        infofly_tip1_tv=findViewById(R.id.infofly_tip1_tv);
        info_levelview=findViewById(R.id.info_levelview);

       // ViewUtils.setTextViewStr(infofly_valueunit_tv,"%");

    }


    @Override
    protected void initData(Bundle arguments) {

        String tip=getString(R.string.str_BMI_introduce);
        infofly_tip1_tv.setText(tip);



        //执行了这一句 下面的UpdateCurrentMesureInfo接口会回调display方法
        if (getParentFragment()!=null){
            ((Info_Fragment)getParentFragment()).getCurrentDisplayInfo(TAG);
        }
    }


    @Override
    public void UpdateCurrentMesureInfo(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {

        displayBMI(currentMeasureRecord);
    }

    float[] middle = new float[]{18.5f,24f,28f};
    int[] colors = new int[]{
            Color.parseColor("#49D8F1"),
            Color.parseColor("#54BF4B"),
            Color.parseColor("#EFB847"),
            Color.parseColor("#EE7D65"),
    };
    String[] buttoms=new String[]{
            StringUtils.getResStr(R.string.piandi),
            StringUtils.getResStr(R.string.biaozhun),
            StringUtils.getResStr(R.string.piangao),
            StringUtils.getResStr(R.string.chaozhong)};

    private void displayBMI(SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        if (info_levelview==null)return;

        info_levelview.setDisInfo(middle,colors,buttoms);
        info_levelview.setMinMaxValuse(0,40);

        if (currentMeasureRecord!=null){
            if (currentMeasureRecord.bmi!=0){
                info_levelview.setDrawWujiaoxin((true));
                ViewUtils.setTextViewStr(infofly_value_tv,currentMeasureRecord.bmi+"");
            }else if (currentMeasureRecord.bmi == 0){
                info_levelview.setDrawWujiaoxin((false));
                ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
            }
            info_levelview.displayValue(currentMeasureRecord.bmi);
        }else {
            info_levelview.setDrawWujiaoxin((false));
            ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
            info_levelview.displayValue(0);
        }



    }
}
